
package com.chixing.day09_innerclass;


public class StringDemo {
    public static void main(String[] args) {
        String word = "Strings are constant; their values cannot" +
                " be changed after they  are created" ;

        char[] chars = word.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            System.out.println(chars[i]);
        }

        int code1= word.codePointAt(0);
        int code5= word.codePointAt(4);

        boolean not = word.contains("not");

        int len = word.length();

        byte[] bytes = word.getBytes();

        int e = word.indexOf("e");

        int an = word.indexOf("an");

        int e2 = word.lastIndexOf("e");

        String a = word.replaceAll("a","A");

        String z = word.toUpperCase();

        String Z = word.toLowerCase();




        String s1 = "hello";
        s1 = " good";
        System.out.println(s1);

        String s2 = new String("code"); // 堆
        String s3 = "code";   //字符串常量池
        System.out.println("s2==s3? :"+(s2 == s3)); //false

        String s4 = "file";
        String s5 = "file";
        System.out.println("s4 == s5 ? :"+(s4 == s5));//true ==比较的是内存地址

        String s6 = new String("help");
        String s7 = new String("help");
        System.out.println("s6==s7?:"+(s6 == s7));
        String s8 = "help";

        /**
         * String s1 = "a";
         * String s2 = "b";
         *
         * s1+s2 = = => new String("ab") 堆
         * s1.concat(s2) == => new String("ab") 堆
         *
         * "a"+"b" = = => 在常量池中 放一份 “ab”
         *
         */


        String str1 = "hello";
        String str2 = "world";
        String str3 = str1 + str2; // new String("helloworld")
        String str4 = "helloworld";
        System.out.println("str3 == str4 :" + (str3 == str4)); //false


        String str0 = "hello" + "world"; // "helloworld" 到常量池中匹配
        System.out.println("str0 == str4 :" + (str0 == str4)); // true


        String str5 = str1 + str2; // new String("helloworld")
        System.out.println("str3 == str5 :" + (str3 == str5)); //false

        String str6 = str1.concat(str2); // new String( "helloworld")
        System.out.println("str3 == str6 :" + (str3 == str6));

    }
}
